package com.lin.generate.controller;

import com.lin.generate.common.anno.ValidateParam;
import com.lin.generate.common.anno.ValidateParams;
import com.lin.generate.common.base.R;
import com.lin.generate.common.enums.Check;
import com.lin.generate.common.vo.request.UserReqVO;
import com.lin.generate.common.vo.response.UserRespVO;
import com.lin.generate.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description 登录相关
 * @Author: z156940l@outlook.com
 * @className LoginController
 * @Date: 2023/6/4 20:53
 */
@RestController
@Api(tags = "用户表管理")
@Slf4j
@RequestMapping(value = "/user")
public class LoginController {

    @Autowired
    IUserService iUserService;

    /**
     * 用户注册
     *
     * @return
     */
    @ValidateParams(
            value ={
                    @ValidateParam(value = Check.IsNotBlank, argName = "vo.name", msg = "请输入用户名"),
                    @ValidateParam(value = Check.IsNotBlank, argName = "vo.account", msg = "请输入-登录账号"),
                    @ValidateParam(value = Check.IsNotBlank, argName = "vo.password", express = "8-16", msg = "请输入密码"),
            }
    )
    @PostMapping("/register")
    @ApiOperation(httpMethod = "POST", value = "用户注册")
    public R<UserRespVO> register(@RequestBody UserReqVO vo) {
        return R.ok(iUserService.register(vo));
    }

    /**
     * 新增用户表
     *
     * @return
     */
    @ValidateParams(
            value ={
                    @ValidateParam(value = Check.IsNotBlank, argName = "vo.account", msg = "请输入-登录账号"),
                    @ValidateParam(value = Check.IsNotBlank, argName = "vo.password", express = "8-16", msg = "请输入密码"),
            }
    )
    @PostMapping("/save")
    @ApiOperation(httpMethod = "POST", value = "用户登录")
    public R<UserRespVO> login(@RequestBody UserReqVO vo) {
        return R.ok(iUserService.login(vo));
    }
}
